<?
ob_start();
// if ($_SESSION['memberID']==1 && $_SESSION['dtype']==9) {
if (($_SESSION['sdtype']==9 && strpos($_SESSION['qx'],'orderReport') )|| $_SESSION['memberID']==1) {
    header('location:admin/orderReport.html');
    exit;
}
//pzp 九天要的直接查看这个页面不要登录 我最讨厌给别人订制什么东西了
if(
    !$_SESSION['sid'] && !$_SESSION['memberID'] && !$_SESSION['dtype'] && !$_SESSION['saccount'] &&
    $_GET['account'] == 504659 &&  //三亚湾红树林
    $_GET['token'] == md5(123456)  //e10adc3949ba59abbe56e057f20f883e
){
    $_SESSION = array(
                     'sid'=>'24705','memberID'=>'24705','dtype'=>'0','sdtype'=>'0',
                     'account'=>'504659','saccount'=>'504659',
                     'dname'=>'三亚湾红树林'
                     );
}
include("common/header.html");
include('common/autoload.php');
$out_html = ob_get_contents();
ob_end_clean();
include_once("class/ProOrder.php");
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = SoapInit::GetSoapInside();
$memberID=$_SESSION['sid'];

// 异步获取对应的景点门票
if($_SERVER['HTTP_REQUEST_TYPE']=='getTicket'){
	$sql='SELECT id,title FROM uu_jq_ticket WHERE landid='.($_REQUEST['landid']+0);//
	$GLOBALS['le']->query($sql);
	$tickes = array();
	while($row=$GLOBALS['le']->fetch_assoc()){
		$tickes[]=$row;
	}
	if(count($tickes)){
		echo json_encode(array('s'=>'success','content'=>$tickes));
	}else{
		echo json_encode(array('s'=>'fail'));
	}
	exit;
}
//供应商身份获取他的分销商
if($_SESSION['dtype']==0 || $_SESSION['dtype']==1|| $_SESSION['dtype']==6 || $_SESSION['dtype']==7) {
    include 'getDistors.php';
    $memberID = ($_SESSION['dtype']==6 || $_SESSION['dtype']==7) ? $_SESSION['sid']:$_SESSION['memberID'];
    if($_SESSION['dtype']==7){
        $DistorsNames = getAll($GLOBALS['le'],$memberID);
    }else{
        $DistorsNames = getRetail($GLOBALS['le'],$memberID);
    }
    //TODO::加载会员数据 ---By Cgp
    $memberNames = require dirname(__FILE__) . '/module/link_product/Member.cache.php';
    $dTypeName =  '分销商';
}
//if($_GET['cs'])
//    print_r($DistorsNames);
$DistorsNames['1sanke'] = '散客';
//管理员
if($_SESSION['memberID']==1 && $_SESSION['dtype']==9){
    $aDistorsNames=array();
    $sql='SELECT id,dname FROM pft_member';
    $GLOBALS['le']->query($sql);
    while($row=$GLOBALS['le']->fetch_assoc()){
        $aDistorsNames[$row['id']]=$row['dname'];
    }
}
if(!$_REQUEST['begintime'] && !$_REQUEST['endtime'])
    goto one;
$btime=$_REQUEST['begintime']?trim($_REQUEST['begintime']):date("Y-m-d",strtotime('-7days'));
$etime=$_REQUEST['endtime']?trim($_REQUEST['endtime']):date("Y-m-d");
$btime = strpos($btime,":")!==false?$btime : $btime." 00:00:00";
$etime = strpos($etime,":")!==false?$etime : $etime." 23:59:59";
$by=$_REQUEST['by']?$_REQUEST['by']:"lid";
$option=array();
if(count($_REQUEST['status'])>0){
	$option['status']=implode("|",$_REQUEST['status']);
}

// 景点查询
if(isset($_REQUEST['landid']))	$option['lid']=$_REQUEST['landid'];

// 门票查询
if(isset($_REQUEST['ticket'])){
	$t = explode("_",$_REQUEST['ticket']);$option['tid']=$t[0];
}

//交易时间类型
$timeType = isset($_REQUEST['xtimes'])? abs($_REQUEST['xtimes']) : 1;
//分销商ID
$fid = isset($_REQUEST['fid']) ? abs($_REQUEST['fid']) : 0;
//TODO::直销
$obj = saleProOrderObject($memberID,$s,$_SESSION['sdtype']);
if($_SESSION['dtype']==7){
    //7集团帐号
	$r = $obj->orderSum($btime,$etime,$by,
        $option, $timeType, $fid);
}else{
    /*
    if($_GET['xtimes']==3){
        $_GET['aid'] = $_SESSION['sid'];
        include_once 'module/zax/order_report/cetX.php';
        goto one;
    }
    */
	$r = $obj->_orderSum($btime,$etime,$by,$option, $timeType, $fid);
}




if($_SESSION['dtype']!=7 && $_SESSION['dtype']!=9 && $_GET['order_type']!=2){
	if($_REQUEST['by']=='mid'){
		foreach($r as $k => $v){
            if($k==0) {
                $r[$k]['title'] = '<span style="color:red;">'.$memberNames[$_SESSION['memberID']].'(自供自销)</span>';
            }
			else if($_SESSION['memberID']==1 && $_SESSION['dtype']==9){
                $r[$k]['title']=$aDistorsNames[$k];
			}else{
                $r[$k]['title']=$memberNames[$k];
			}
		}
	}
}else if($_REQUEST['by']=='mid' && $_GET['order_type']==2){
    foreach($r as $k => $v){
        //取消订单里面 $k的组成是mid+时间  先取到时间里的 横杠的位置 然后往前再取4位
        $time_pos = strpos($k,'-');
        $mid = substr($k,0,$time_pos-4);
        $r[$k]['title']=$memberNames[$mid];
    }
}


$totals=array();
/*导出EXCEL处理程序--begin-*/
//include("ExcelHandle.php");
/*导出EXCEL处理程序--end*/



// 获取产品
$products = $obj->getOrderProducts(); // 订单中的产品列表
//print_r($products );
if($_REQUEST['proList']){ //以有产品列表比查询出来的少更新
	$tmp = unserialize($_REQUEST['proList']);
	if(count($products)<=count($tmp)){
		$products = $tmp;
		$proList = serialize($tmp); 
	}else{
		$proList = serialize($products);
	}
}else{
	$proList = serialize($products);
}
one:

$titleT=array("lid"=>"景区名称","tid"=>"票类名称","mid"=>"分销商名称");
echo $out_html;
$from="sale";
//取景点
$land = array();
include("/var/www/html/new/d/class/Member.php");
$m = new Member($s,$memberID);
$sale = $m->salePros();
foreach($sale as $v){
    if(!$land[$v['lid']])
    $land[$v['lid']]= $v['title'];
}

include("tpl/orderReport.tpl");
include("common/footer.html");
?>